package com.house.user.entity;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;


/**
 * Role entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name="t_role")

public class Role  implements java.io.Serializable {


    // Fields    

     private Integer roleId;
     private Integer parentId;
     private String roleName;
     private String description;
     private Set<User> users = new HashSet<User>(0);
     private Set<Right> rights = new HashSet<Right>(0);


    // Constructors

    /** default constructor */
    public Role() {
    }

	/** minimal constructor */
    public Role(Integer parentId, String roleName) {
        this.parentId = parentId;
        this.roleName = roleName;
    }
    
    /** full constructor */
    public Role(Integer parentId, String roleName, String description, Set<User> users, Set<Right> rights) {
        this.parentId = parentId;
        this.roleName = roleName;
        this.description = description;
        this.users = users;
        this.rights = rights;
    }

   
    // Property accessors
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    
    @Column(name="role_id", unique=true, nullable=false)

    public Integer getRoleId() {
        return this.roleId;
    }
    
    public void setRoleId(Integer roleId) {
        this.roleId = roleId;
    }
    
    @Column(name="parent_id", nullable=false)

    public Integer getParentId() {
        return this.parentId;
    }
    
    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }
    
    @Column(name="roleName", nullable=false, length=20)

    public String getRoleName() {
        return this.roleName;
    }
    
    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }
    
    @Column(name="description", length=50)

    public String getDescription() {
        return this.description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="roles")

    public Set<User> getUsers() {
        return this.users;
    }
    
    public void setUsers(Set<User> users) {
        this.users = users;
    }
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinTable(name="t_role_right", catalog="house", joinColumns = { 
        @JoinColumn(name="role_id", nullable=false, updatable=false) }, inverseJoinColumns = { 
        @JoinColumn(name="right_id", nullable=false, updatable=false) })

    public Set<Right> getRights() {
        return this.rights;
    }
    
    public void setRights(Set<Right> rights) {
        this.rights = rights;
    }
   








}